package com.dingding.webservice.banner.impl;

import java.util.List;

import com.dingding.bean.databean.request.ReqBannerShow;
import com.dingding.bean.databean.request.ReqBannerShowByType;
import com.dingding.bean.databean.response.DataResponse;
import com.dingding.common.core.beans.BannerImage;
import com.dingding.common.core.config.SystemCode;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.service.BaseService;
import com.dingding.webservice.banner.IBannerInfoService;

/**
 * @ClassName: BannerShowServiceImpl
 * @Description:  Banner显示模块实现类
 * @author yuHaiQing
 * @date 2016年3月29日 下午3:12:31
 */
public class BannerInfoServiceImpl extends BaseService implements IBannerInfoService {

	/**
	 * @Title: getBannerList
	 * @Description: 获取全部有效的请求Bean
	 * @author yuHaiQing
	 * @return void    返回类型
	 */
	@Override
	public void getBannerList(ReqBannerShow reqBannerShow, DataResponse dataResponse) {

		// 判断客户端请求参数是否为空
		if (reqBannerShow == null || reqBannerShow.getBannerImageType() == null
				|| reqBannerShow.getBannerShowType() == null) {
			setStatus(dataResponse, SystemCode.DATA_NULL_ERROR);
			return;
		}

		// 获取Banner列表
		List<BannerImage> bannerImages = super.bannerFacade.getBannerList(reqBannerShow.getBannerShowType(),
				reqBannerShow.getBannerImageType());

		// 将获取到的优惠券信息赋值给dataResponse
		dataResponse.setResponseBody(bannerImages);

		setStatus(dataResponse, SystemCode.SUCCESS);

	}

	
	/**
	 * @Title: getBannerListByType
	 * @Description: 根据模块类型获取全部有效的请求Bean
	 * @param reqBannerShowByType 获取Banner的请求参数
	 * @author yuHaiQing
	 * @since V2.5.5
	 * @return void    返回类型
	 */
	@Override
	public void getBannerListByType(ReqBannerShowByType reqBannerShowByType, DataResponse dataResponse) {

		// 判断客户端请求参数是否为空
		if (reqBannerShowByType == null || reqBannerShowByType.getBannerImageType() == null
				|| reqBannerShowByType.getBannerShowType() == null || reqBannerShowByType.getUseType() == null) {
			setStatus(dataResponse, SystemCode.DATA_NULL_ERROR);
			return;
		}

		// 获取Banner列表
		List<BannerImage> bannerImages = super.bannerFacade.getBannerListByType(reqBannerShowByType.getBannerShowType(),
				reqBannerShowByType.getBannerImageType(),reqBannerShowByType.getUseType());

		// 将获取到的优惠券信息赋值给dataResponse
		dataResponse.setResponseBody(bannerImages);

		setStatus(dataResponse, SystemCode.SUCCESS);

	}
	
	/**
	 * @Title: getBannerInfo
	 * @Description: 获取活动详情
	 * @param reqBannerShow 获取活动详情的请求参数
	 * @param dataResponse  响应客户端的数据传输Bean
	 * @author yuHaiQing
	 * @return void    返回类型
	 */
	@Override
	public void getBannerInfo(ReqBannerShow reqBannerShow, DataResponse dataResponse) {

		// 判断客户端请求参数是否为空
		if (reqBannerShow == null || ToolUtil.isBlank(reqBannerShow.getBannerImageId())) {
			setStatus(dataResponse, SystemCode.DATA_NULL_ERROR);
			return;
		}

		// 获取Banner详情
		BannerImage bannerImage = super.bannerFacade.getBannerInfo(reqBannerShow.getBannerImageId());

		// 将获取到的优惠券信息赋值给dataResponse
		dataResponse.setResponseBody(bannerImage);

		setStatus(dataResponse, SystemCode.SUCCESS);

	}

	@Override
	public void setStatus(DataResponse dataResponse, int status) {

		String message = null;
		switch (status) {
		case SystemCode.SUCCESS:
			message = SystemCode.SUCCESS_MESSAGE;
			break;
		case SystemCode.ERROR:
			message = SystemCode.ERROR_MESSAGE;
			break;
		case SystemCode.USER_INFO_NOT_EXIST_ERROR: // 用户信息不存在
			message = SystemCode.USER_INFO_NOT_EXIST_MESSAGE;
			break;
		case SystemCode.CANCEL_ORDER_TOO_MUCH: // 取消次数超过三次
			message = SystemCode.CANCEL_ORDER_MUCH_MESSAGE;
			break;
		case SystemCode.PUBLISH_ORDER_TOO_MUCH: // 接单次数超过三次
			message = SystemCode.PUBLISH_ORDER_TOO_MUCH_MESSAGE;
			break;
		case SystemCode.DATA_NULL_ERROR: // 请求数据为空
			message = SystemCode.DATA_NULL_MESSAGE;
			break;
		case SystemCode.COUPON_ACTIVATION_FAIL:
			message = SystemCode.COUPON_ACTIVATION_FAIL_MESSAGE;// 优惠券激活失败
			break;
		case SystemCode.STORE_LOAG_NULL:
			message = SystemCode.STORE_LOAD_NULL_MESSAGE;// 使用优惠券失败
			break;
		default:
			break;
		}
		dataResponse.setResponseCode(status);
		dataResponse.setResponseMessage(message);

	}

}
